package com.ucar.train.web;

import com.ucar.train.service.xumingzhi.Car;
import com.ucar.train.service.xumingzhi.Process.ChangeFilterElement;
import com.ucar.train.service.xumingzhi.Process.PlusTirePressure;
import com.ucar.train.service.xumingzhi.Process.ProcessTemplate;
import com.ucar.train.service.xumingzhi.Process.RefuelingOil;
import com.ucar.train.service.xumingzhi.ResultUtil.CarStateEnum;
import com.ucar.train.service.xumingzhi.ResultUtil.Result;
import com.ucar.train.service.xumingzhi.vo.MaintainVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

/**
 * Desciption:
 *
 * @Author: XuMingZhi.
 * Creation time: 2019/8/22 13:12:00.
 * © Copyright 2013-2019, UCar.
 */
@Controller
@RequestMapping("/maintain")
public class MaintainController {

    /**
     * 功能描述: <br>
     * 〈保养车辆〉
     * @Param: [maintainVO]
     * @Return: org.springframework.web.servlet.ModelAndView
     * @Author: XuMingZhi
     * @Date: 2019/8/22 14:39
     */
    @RequestMapping(value = "/xmz", method = RequestMethod.POST)
    public ModelAndView xmz(MaintainVO maintainVO){
        Car car = new Car();
        car.addProcess(select(maintainVO.getProcessone()));
        car.addProcess(select(maintainVO.getProcesstwo()));
        car.addProcess(select(maintainVO.getProcessthree()));
        car.setCarStateEnum(CarStateEnum.MAINTAINING);//设置状态 保养中
         Result result=car.maintenance();
        System.out.println(result.toString());
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("result",result.toString());
        modelAndView.setViewName("maintain-show");
        return modelAndView;
    }

    /**
     * 功能描述: <br>
     * 〈选择模板〉
     * @Param: [code]
     * @Return: com.ucar.train.service.xumingzhi.Process.ProcessTemplate
     * @Author: XuMingZhi
     * @Date: 2019/8/22 14:39
     */
    ProcessTemplate select(int code){
        if(code==0){
            return new ChangeFilterElement();
        }else if(code==1){
            return new PlusTirePressure();
        }else if(code==2){
            return new RefuelingOil();
        }
        return null;
    }
}
